#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace XnaGameComponents
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Cube : GameComponent
    {
        private ExtrudableQuad cube;

        public ExtrudableQuad EQuad
        {
            get { return cube; }
        }

        public BoundingBox BoundingBox
        {
            get { return cube.BoundingBox; }
            set { cube.BoundingBox = value; }
        }

        public Cube(Game game)
            : base(game)
        {
            cube = new ExtrudableQuad(game);
            game.Components.Add(cube);
        }

        private Vector3 dimensions;

        public Vector3 Dimensions
        {
            get { return dimensions; }
            set { dimensions = value; }
        }

        private Vector3 origin;

        public Vector3 Origin
        {
            get { return origin; }
            set { origin = value; }
        }

        private Vector3 forward;

        public Vector3 Forward
        {
            get { return forward; }
            set { forward = value; }
        }

        private Vector3 up;

        public Vector3 Up
        {
            get { return up; }
            set { up = value; }
        }




        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            /*     ___________
             *    /|        / |
             *   / |  5    /  |
             *  /__|____2_/   |
             * | 3 |      | 1 |
             * |   |______|___|
             * |  /  0    |  /
             * | /     4  | /
             * |/_________|/
             */
            if (forward == Vector3.Zero)
                forward = Vector3.Forward;
            if (up == Vector3.Zero)
                up = Vector3.Up;
            Vector3 left=Vector3.Cross(forward,up);
            cube.Height = dimensions.Y;
            cube.LowerRight = origin - dimensions.X / 2f * left - dimensions.Z / 2f * up;
            cube.LowerLeft = origin + dimensions.X / 2f * left - dimensions.Z / 2f * up;
            cube.UpperRight = origin - dimensions.X / 2f * left + dimensions.Z / 2f * up;
            cube.UpperLeft = origin + dimensions.X / 2f * left + dimensions.Z / 2f * up;
            base.Initialize();
        }
    }
}


